#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<stack>
using namespace std;
const int N = 3e6;
int a[N],n;
int ret[N];
void test1()
{
	stack<int> as;
	for (int i = 1; i <= n; i++)
	{
		while (as.size() && a[as.top()] <= a[i])
		{
			as.pop();
		}
		if (as.size())
		{
			ret[i] = as.top();
		}
		as.push(i);
	}
	for (int i = 1; i <= n; i++)
	{
		cout << ret[i] << " ";
	}
}
void test2()
{
	stack<int> as;
	for (int i = 1; i <= n; i++)
	{
		while (as.size() && a[as.top()] >= a[i])
		{
			as.pop();
		}
		if (as.size())
		{
			ret[i] = as.top();
		}
		as.push(i);
	}
	for (int i = 1; i <= n; i++)
	{
		cout << ret[i] << " ";
	}
}
void test3()
{
	stack<int> as;
	for (int i = n; i >=1; i--)
	{
		while (as.size() && a[as.top()] <= a[i])
		{
			as.pop();
		}
		if (as.size())
		{
			ret[i] = as.top();
		}
		as.push(i);
	}
	for (int i = 1; i <= n; i++)
	{
		cout << ret[i] << " ";
	}
}
void test4()
{
	stack<int> as;
	for (int i = n; i >= 1; i--)
	{
		while (as.size() && a[as.top()] >= a[i])
		{
			as.pop();
		}
		if (as.size())
		{
			ret[i] = as.top();
		}
		as.push(i);
	}
	for (int i = 1; i <= n; i++)
	{
		cout << ret[i] << " ";
	}
}
int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
	}
	/*test1();*/
	/*test2();*/
	/*test3();*/
	test4();

	return 0;
}